
<template>
  <div style="height: 100%; width: 100%; position: relative;" ref="maindev">
    <div class="pagetop">
      <table style="width: 100%; font-size: 12px;" border="0">
        <col style="width: 5%;" />
        <col style="width: 8%;" />
        <col style="width: 1%;" />
        <col style="width: 8%;" />
        <col style="width: 4%;" />
        <col style="width: 11%;" />
        <col style="width: 4%;" />
        <col style="width: 11%;" />
        <col style="width: 5%;" />
        <col style="width: 11%;" />
        <col style="width: 5%;" />
        <col style="width: 11%;" />
        <col style="width: 4%;" />
        <col style="width: 11%;" />
        <tr>
          <td align="right">
            <el-dropdown @command="handleCommand" style="font-size: 12px;">
              <u class="el-dropdown-link">
                {{ datename }}
              </u>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="标本日期">
                  <font font-size="12px">标本日期</font>
                </el-dropdown-item>
                <el-dropdown-item command="报告日期">
                  <font font-size="12px">报告日期</font>
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </td>
          <td>
            <el-date-picker v-model="searchobj.strdate" :clearable="false" type="date" placeholder="选择日期"
              value-format="yyyy-MM-dd" style="width: 100%;"> </el-date-picker>
          </td>
          <td>至</td>
          <td>
            <el-date-picker v-model="searchobj.enddate" type="date" :clearable="false" placeholder="选择日期"
              value-format="yyyy-MM-dd" style="width: 100%;"> </el-date-picker>
          </td>
          <td align="right">科室</td>
          <td>
            <el-select v-model="searchobj.reqdept"
              @dblclick.native="popMultipleChk(searchobj.reqdept, 'reqdept', deptOption, '申请科室选择')" style="width: 100%;"
              filterable clearable>
              <el-option v-for="(item, index) in deptOption" :key="index" :value="item.data" :label="item.display">
              </el-option>
            </el-select>
          </td>
          <td align="right">菌组</td>
          <td>
            <el-select v-model="searchobj.germcomb"
              @dblclick.native="popMultipleChk(searchobj.germcomb, 'germcomb', germcombOption, '细菌组')"
              style="width: 100%;" filterable clearable>
              <el-option v-for="(item, index) in germcombOption" :key="index" :value="item.data" :label="item.display">
              </el-option>
            </el-select>
          </td>
          <td align="right">耐药机制</td>
          <td>
            <el-select v-model="searchobj.resistrule"
              @dblclick.native="popMultipleChk(searchobj.resistrule, 'resistrule', rescodeOption, '耐药机制选择')"
              style="width: 100%;" filterable clearable>
              <el-option v-for="(item, index) in rescodeOption" :key="index" :value="item.data" :label="item.display">
              </el-option>
            </el-select>
          </td>
          <td align="right">病区</td>
          <td>
            <el-select v-model="searchobj.reqward"
              @dblclick.native="popMultipleChk(searchobj.reqward, 'reqward', wardOption, '病区选择')" style="width: 100%;"
              filterable clearable>
              <el-option v-for="(item, index) in wardOption" :key="index" :value="item.data" :label="item.display">
              </el-option>
            </el-select>
          </td>
          <td align="right">样本</td>
          <td>
            <el-select v-if="searchobj.nogermflag == '0'" v-model="searchobj.sample"
              @dblclick.native="popMultipleChk(searchobj.sample, 'sample', specimenOption, '请选择样本')" style="width: 100%;"
              filterable clearable>
              <el-option v-for="(item, index) in specimenOption" :key="index" :value="item.data"
                :label="item.display"></el-option>
            </el-select>
            <el-select v-if="searchobj.nogermflag == '1'" v-model="searchobj.sample"
              @dblclick.native="popMultipleChk(searchobj.sample, 'sample', nogermOption, '请选择样本')" style="width: 100%;"
              filterable clearable>
              <el-option v-for="(item, index) in nogermOption" :key="index" :value="item.data"
                :label="item.display"></el-option>
            </el-select>
          </td>
        </tr>
        <tr>
          <td align="right">报告单元</td>
          <td colspan="3">
            <el-select v-model="searchobj.rptunitid"
              @dblclick.native="popMultipleChk(searchobj.rptunitid, 'rptunitid', rptunitOption, '请选择报告单元')" filterable
              clearable style="width:100%">
              <el-option v-for="(item, index) in rptunitOption" :key="index" :value="item.data"
                :label="item.display"></el-option>
            </el-select>
          </td>
          <td align="right">科室组</td>
          <td>
            <el-select v-model="searchobj.deptgroup"
              @dblclick.native="popMultipleChk(searchobj.deptgroup, 'deptgroup', deptgroupOption, '请选择科室组')"
              style="width: 100%;" filterable clearable>
              <el-option v-for="(item, index) in deptgroupOption" :key="index" :value="item.data"
                :label="item.display"></el-option>
            </el-select>
          </td>
          <td align="right">性别</td>
          <td>
            <el-select v-model="searchobj.patsex" placeholder="请选择性别" style="width: 100%;" :clearable="true">
              <el-option value="1" label="男">男</el-option>
              <el-option value="2" label="女">女</el-option>
              <el-option value="3" label="未知">未知</el-option>
            </el-select>
          </td>

          <td align="right">病人类型</td>
          <td>
            <rm-ddl-common datatype="seccode" kindno="PT" dataname="病人类型" v-model="searchobj.pattype"
              @change="pattypeChange" width="100%"></rm-ddl-common>
          </td>
          <!-- <td align="right">统计科室</td>
                  <td>
                      <el-select v-model="bytype" placeholder="请选择统计类别;科室/病区" style="width: 100%;">
                          <el-option value="1" label="按科室统计"></el-option>
                          <el-option value="2" label="按病区统计"></el-option>
                      </el-select>
                  </td> -->
          <td></td>
          <td>
            <el-checkbox true-label="1" false-label="0" v-model="searchobj.bypat">按病人统计</el-checkbox>
            <!-- <el-checkbox true-label="1" false-label="0" v-model="deptmode">仅按科室病区统计标本数</el-checkbox> -->
          </td>
          <td></td>
          <td>
            <el-checkbox true-label="1" false-label="0" v-model="searchobj.nogermflag">仅显示无菌样本</el-checkbox>
          </td>
        </tr>
        <tr>
          <td align="right"><span @click="Btncountitem"
              style="color:#F56C6C;font-weight:bold;boder-color:#DCDFE6;cursor: pointer;font: size 14px;">统计项目</span></td>
          <td @click="Btncountitem"
            style="height:26px;color:blue;font-weight:bold;border: 1px solid #DCDFE6;cursor: pointer;" colspan="5">
            <div style="text-align:center;" v-if="infocode == ''" @click="Btncountitem">
              <span style="color:#F56C6C;cursor:pointer;font-weight:bold;font-size:13px"> 点击此处选择统计项目</span>
            </div>
            <div v-else>
              <div @click="Btncountitem" style="width:100%;height: 100%;"> <u style="0 0 0 5px">{{ infoitem }}</u>
              </div>
              <el-input v-model="infocode" readonly v-show="false"></el-input>
            </div>
          </td>
          <td align="right">细菌标志</td>
          <td>
            <el-select v-model="searchobj.germflag" placeholder="请选择" style="width:100%" filterable clearable>
              <el-option key="0" label="普通项目" value="0"></el-option>
              <el-option key="1" label="培养阴性结果" value="1"></el-option>
              <el-option key="2" label="致病菌" value="2"></el-option>
              <el-option key="3" label="正常菌种" value="3"></el-option>
              <el-option key="4" label="涂片结果" value="4"></el-option>
            </el-select>
          </td>
          <td></td>
          <td></td>
          <td></td>
          <td>
            <el-checkbox true-label="1" false-label="0" v-model="searchobj.medflag">仅显示带药敏</el-checkbox>
          </td>
        </tr>

        <tr>
          <td colspan="14" align="right">
            <el-button @click.native="btnQuery" v-has="'PINQUERY'" type="primary" icon="el-icon-search">查询</el-button>
            <!-- <el-button @click.native="btnSort" icon="el-icon-sort">排序</el-button> -->
            <el-button @click.native="btnClear" icon="el-icon-close">清除</el-button>
            <el-button @click.native="btnExport" icon="el-icon-upload2">导出</el-button>
            <!-- <el-button icon="el-icon-printer" @click="btnPrint(1)">打印</el-button>
                      <el-button icon="el-icon-zoom-in" @click="btnPrint(2)">预览</el-button>
                      <el-button icon="el-icon-printer" @click="btnPrint(3)">设计</el-button> -->
          </td>
        </tr>
      </table>
    </div>
    <div class="pagecenter">
      <div class="middle-center">
        <vxe-table :data.sync="tableData" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" border
          height="auto" highlight-current-row class="mytable-style" highlight-hover-column highlight-hover-row
          ref="xTable" resizable size="mini" stripe :optimization="{ animat: true }" header-align="center"
          :key="xTablekey" show-footer :footer-method="footerMethod" :loading="bLoading"
          :footer-cell-class-name="footerCellClassName" :cell-class-name="cellClassName" @cell-dblclick="xTabledblclick">
          <vxe-table-column :field="items.field" :key="items.name" :title="items.name" :width="items.width" sortable
            align="center" v-for="items in tableColumn" :formatter="formatFun"></vxe-table-column>
        </vxe-table>
      </div>
    </div>
    <!--报告项目--->
    <el-dialog width="1000px" top="10px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false"
      title="报告项目" :visible.sync="dialogTableVisible1" :destroy-on-close="true">
      <rm-pop-selrptitem @cancel="dialogTableVisible1 = false" @selitem="addrptitem"></rm-pop-selrptitem>
    </el-dialog>
    <!--多选弹窗--->
    <el-dialog width="900px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :title="multichktitle"
      :visible.sync="dialogMultipleVisible" :destroy-on-close="true">
      <rm-SqlMultiple :leftOption="option1" :rightOption="option2" :name="fieldname"
        @change="closedialog"></rm-SqlMultiple>
    </el-dialog>
    <!--统计项目-->
    <el-dialog title="统计项目" :visible.sync="dialogcountItem" width="800px" v-el-drag-dialog :append-to-body="true"
      :close-on-click-modal="false">
      <div style="width: 100%; height: 300px; margin-top: 5px;">
        <div style="width: 70%; height: 100%; float: left; overflow: auto; border: 1px solid #ccc;">
          <div id="left_nav" class="left_nav">

            <div @click="showseq = 1" :class="showseq == 1 ? 'active' : ''" ref="left1">
              1 检验信息
            </div>
          </div>
          <div id="right_nav" class="right_nav">
            <table class="table1style" style="width: 100%; padding: 10px;">
              <tr v-show="showseq == 1">
                <td>
                  <el-checkbox @change="chkcountitem($event, '细菌名称', 'rp_rpt_itemname')"
                    v-model="rp_rpt_itemname">细菌名称</el-checkbox>
                </td>
                <td>
                  <el-checkbox @change="chkcountitem($event, '所属病区', 'rp_req_wardno')"
                    v-model="rp_req_wardno">所属病区</el-checkbox>
                </td>
                <td>
                  <el-checkbox @change="chkcountitem($event, '申请科室', 'rp_req_deptno')"
                    v-model="rp_req_deptno">申请科室</el-checkbox>
                </td>
              </tr>
              <tr v-show="showseq == 1"></tr>
              <tr v-show="showseq == 1">
                <td>
                  <el-checkbox @change="chkcountitem($event, '年', 'rp_sampleyear')"
                    v-model="rp_sampleyear">年(YYYY)</el-checkbox>
                </td>
                <td>
                  <el-checkbox @change="chkcountitem($event, '月', 'rp_samplemonth')"
                    v-model="rp_samplemonth">月(YYYYMM)</el-checkbox>
                </td>
                <td>
                  <el-checkbox @change="chkcountitem($event, '日', 'rp_sampleday')"
                    v-model="rp_sampleday">日(YYYY/MM/dd)</el-checkbox>
                </td>
              </tr>
            </table>
          </div>
        </div>
        <div style="width: 29%; height: 100%; float: left; margin-left: 5px; overflow: auto;">
          <vxe-table show-overflow ref="xTable1" height="auto" :select-config="{ reserve: true }"
            :sort-config="{ trigger: 'cell' }" :mouse-config="{ selected: true }" :data.sync="tableData1" border
            size="mini" show-header-overflow highlight-current-row highlight-hover-row resizable stripe
            @current-change="currentChangeEvent1" @cell-dblclick="xTable1dblclick">
            <vxe-table-column type="index" title="NO." width="50" align="center"></vxe-table-column>
            <vxe-table-column field="countitem" title="统计项目(双击删除)" width="160" sortable
              header-align="center"></vxe-table-column>
          </vxe-table>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button icon="el-icon-top" @click="tabledatafirst()">首位</el-button>
        <el-button icon="el-icon-top-right" @click="tabledataup()">上移</el-button>
        <el-button icon="el-icon-bottom-right" @click="tabledatadown()">下移</el-button>
        <el-button icon="el-icon-bottom" @click="tabledatalast()">末位</el-button>
        <el-button @click="tableClear">清 除</el-button>
        <el-button type="primary" @click="dialogcountItemsave">确 定</el-button>
        <el-button @click="dialogcountItem = false">取 消</el-button>
      </span>
    </el-dialog>
    <!--病人信息-->
    <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="病人信息"
      :visible.sync="dialogShowPatinfo" width="900px">
      <div style="height: 550px">
        <vxe-table :data.sync="patinfoTableData" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }"
          border height="100%" highlight-current-row class="mytable-style" highlight-hover-column highlight-hover-row
          how-header-overflow ref="xTable_patinfo" resizable show-overflow size="mini" stripe show-header-overflow
          header-align="center" show-footer>
          <vxe-table-column field="pat_no" sortable title="病人号" align="center" width="90"
            show-overflow></vxe-table-column>
          <vxe-table-column field="pat_name" sortable title="姓名" align="center" width="70"
            show-overflow></vxe-table-column>
          <vxe-table-column field="pat_sex" sortable title="性别" align="center" width="50"
            show-overflow></vxe-table-column>
          <vxe-table-column field="pat_agestr" sortable title="年龄" align="center" width="70"
            show-overflow></vxe-table-column>
          <vxe-table-column field="pat_typename" sortable title="病人类别" align="center" width="80"
            show-overflow></vxe-table-column>
          <vxe-table-column field="req_dt" sortable title="申请时间" align="center" width="130"
            :formatter="['toDateString', 'yyyy-MM-dd HH:mm:dd']" show-overflow></vxe-table-column>
          <vxe-table-column field="sampled_dt" sortable title="采样时间" align="center" width="130"
            :formatter="['toDateString', 'yyyy-MM-dd HH:mm:dd']" show-overflow></vxe-table-column>
          <vxe-table-column field="report_user" sortable title="检验医生" align="center" width="70"
            show-overflow></vxe-table-column>
          <vxe-table-column field="req_reason" sortable title="送检目的" align="left" width="190"
            show-overflow></vxe-table-column>
        </vxe-table>
      </div>
    </el-dialog>
  </div>
</template>

<script type="text/javascript">
import XEUtils from "xe-utils"
export default {
  name: "LIS921",
  data() {
    return {
      sexOption: [
        { label: "", value: "" },
        { label: "男", value: "1" },
        { label: "女", value: "2" },
      ],
      chargeflagOption: [
        { label: "未收费", value: "0" },
        { label: "已收费", value: "1" },
        { label: "等待退费", value: "8" },
        { label: "已退费", value: "9" },
        { label: "免费", value: "5" },
      ],
      //查询的统计项目
      infoitem: "", //标本类型,项目
      infocode: "", //rp_specimen_code,rp_rpt_itemname
      bLoading: false,
      rp_req_deptno: false,
      rp_req_wardno: false,
      rp_rpt_itemname: false,
      rp_rpt_itemcode: false,
      rp_sampleyear: false,
      rp_samplemonth: false,
      rp_sampleday: false,
      is_showselother: false,
      dialogcountItem: false,
      dialogTableVisible1: false,
      dialogMultipleVisible: false,
      option1: [],
      option2: [],
      txtrptitem: "",
      fieldname: "",
      tableColumn: [],
      tableData: [],
      tableData1: [],
      showseq: 1,
      currRowIndex: 0,
      xTablekey: 0,
      datename: "标本日期",
      multichktitle: "",
      daytype: "1",
      pattypeOption: [],
      deptOption: [],
      wardOption: [],
      hospOption: [],
      doctorOption: [],
      rptunitOption: [],
      rptunitGroupOption: [],
      reportcommOption: [],
      labgroupOption: [],
      //
      rescodeOption: [],
      specimenOption: [],
      nogermOption: [],
      germcombOption: [],
      deptgroupOption: [],
      //以下为查询条件
      searchobj: {
        strdate: this.$pub.InitDateTime2(0).datefrom,
        enddate: this.$pub.InitDateTime2(0).dateto,
        reqdept: "",
        germcomb: "",
        resistrule: "",
        reqward: "",
        sample: "",
        rptunitid: "",
        deptgroup: "",
        patsex: "",
        pattype: "",
        bytype: "",
        bypat: "0",
        nogermflag: "0",
        deptmode: "0",
        germflag: "2",
        medflag: "0",
      },
      //以下为排序数组
      sortArr: [],
      SortTableColumn: [
        { title: "报告数", field: "cp_samplecnt" },
        { title: "检验项目次数", field: "cp_cnt" },
        { title: "金额", field: "cp_amt" },
        { title: "人数", field: "cp_rs" },
        { title: "项目复查数", field: "cp_redocnt" },
      ],
      dialogShowPatinfo: false,
      patinfoTableData: [],
      pattypename: "",
      exportTableColLen: 0,
    }
  },
  created() {
    this.initOption()
    this.initdate() //初始化时间
    // this.InitPage() //初始化主列表
  },
  watch: {
    bSaveResultComb() {
      console.log(this.bSaveResultComb)
    }
  },
  mounted() { },
  updated() { },
  methods: {
    popMultipleChk(e, fieldname, option, title) {
      let temp = XEUtils.clone(option, true)
      this.option1 = []
      this.option2 = []
      if (e != "") {
        let k = e.split(",")
        k.forEach((item) => {
          let ndata = temp.find((m) => m.data == item)
          if (ndata != undefined && ndata != null) {
            this.option2.push(ndata)
          }
        })
        temp.forEach((item) => {
          if (k.indexOf(item.data + "") < 0) {
            this.option1.push(item)
          }
        })
      } else {
        this.option1 = temp
      }
      this.fieldname = fieldname
      this.multichktitle = title
      this.dialogMultipleVisible = true
    },
    closedialog(value, name) {
      if (value != "close") {
        this.searchobj[name] = value
      }
      this.dialogMultipleVisible = false
    },
    //时间初始化
    initdate() {
      var date = new Date()
      this.strdate = XEUtils.toDateString(date, "yyyy-MM-01 00:00:00") //起 始结束日期
      this.enddate = XEUtils.toDateString(date, "yyyy-MM-dd 00:00:00")
    },
    Btncountitem() {
      //重置所有选项
      this.rp_rpt_itemname = false
      this.rp_req_wardno = false
      this.rp_req_deptno = false
      this.rp_sampleyear = false
      this.rp_samplemonth = false
      this.rp_sampleday = false

      this.dialogcountItem = true //开窗
      //表格及checkbox重新赋值
      setTimeout(() => {
        this.$refs.xTable1.tableData = []
        if (this.infoitem != "") {
          let name = this.infoitem.split(",")
          let code = this.infocode.split(",")
          let datas = this.$refs.xTable1.tableData
          for (let i = 0; i < name.length; i++) {
            let finddatas = datas.filter(
              (item) => item.countitem == name[i]
            )
            if (finddatas.length == 0) {
              this.$refs.xTable1
                .insert({
                  countitem: name[i],
                  countcode: code[i],
                })
                .then(({ row }) => {
                  this.$refs.xTable1.setCurrentRow(row)
                })
              this.currRowIndex = name.length - 1
            }
            this[code[i]] = true
          }
        }
      }, 20)
    },
    //选择统计项目
    chkcountitem(e, name, code) {
      let tablelist = this.$refs.xTable1.tableData
      let ishave = tablelist.find((m) => m.countitem == name)
      if (e) {
        if (tablelist.length <= 6) {
          if (ishave == undefined) {
            //防止重复插入
            this[code] = true
            this.$refs.xTable1
              .insert({ countitem: name, countcode: code })
              .then(({ row }) => {
                this.$refs.xTable1.setCurrentRow(row)
                this.currRowIndex = tablelist.length - 1
              })
          }
        } else {
          this[code] = false
          this.$alert("您好，最多只能添加7条统计项目！", "提示", {
            confirmButtonText: "确定",
          })
        }
      } else {
        try {
          if (ishave != undefined) {
            this[code] = false
            var alld = this.$refs.xTable1.tableData
            var rowindex = alld.indexOf(ishave)
            this.$refs.xTable1.remove(ishave)
            let havedata = this.$refs.xTable1.tableData
            if (havedata.length > 0) {
              if (rowindex >= havedata.length)
                rowindex = havedata.length - 1
              let selectrow = havedata[rowindex]
              this.$refs.xTable1.setCurrentRow(selectrow)
              this.currRowIndex = rowindex
            }
          }
        } catch (e) {
          console.log("error", e)
        }
      }
    },
    addrptitem(rptitemcodeinfos) {
      this.txtrptitem = ""
      for (var i = 0; i < rptitemcodeinfos.length; i++) {
        if (this.txtrptitem == "") {
          this.txtrptitem = rptitemcodeinfos[i].rpt_itemcode
        } else {
          this.txtrptitem += "," + rptitemcodeinfos[i].rpt_itemcode
        }
      }
      this.dialogTableVisible1 = false
    },
    currentChangeEvent1({ row, $rowIndex }) {
      this.currRowIndex = $rowIndex
    },
    btnPrint(type) {
      if (rpt_amount > 0) {
        if (type == 3) {
          this.operate = "design"
        } else {
          this.operate = ""
        }
        var sql =
          "sp_print_PositiveList 'sqlwhere:" +
          this.sqlWhere +
          "','operate:'" +
          this.operate +
          "'"

        if (this.styleid) {
          this.$pub.printlistbill(
            this,
            sql,
            type,
            this.styleid,
            "总汇表",
            ""
          )
        } else {
          return this.$message({
            message: "未获取到打印样式id，请刷新页面后重试",
            type: "warning",
          })
        }
      } else {
        this.$message({
          type: "info",
          message: "请先搜索出数据",
        })
      }
    },
    xTabledblclick({ row, column }) {
      console.log(row)
      try {
        //排除无关字段与为零的统计数据
        if (![
          "rp_rpt_itemname",
          "rp_req_wardno",
          "rp_req_deptno",
          "rp_sampleyear",
          "rp_samplemonth",
          "rp_sampleday",
          "检出数",
          "检出人数"
        ].includes(column.property)) {
          if (parseInt(row[column.property]) > 0) {
            var columnname = column.property;
            //获取病人信息
            this.$tool
              .request({
                url: "LIS/LIS9/LIS921",
                method: "post",
                timeout: 600000,
                data: {
                  action: "getDetailsQuery",
                  columnname: columnname,//标本名
                  rowdata: row,
                  daytype: this.daytype, //标本日期(1) 报告日期(2)
                  infocode: this.infocode, //要查询的列数
                  ...this.searchobj,
                },
              })
              .then((res) => {
                this.patinfoTableData = res.data;
                this.dialogShowPatinfo = true;
              })
              .catch((e) => {
                this.$message.warning(e);
              });
          }
        }
      } catch (e) {
        console.log("error", e);
      }
    },
    tabledataup() {
      if (this.currRowIndex > 0) {
        let upData = this.$refs.xTable1.tableData[this.currRowIndex - 1]
        let currentrow = this.$refs.xTable1.tableData[this.currRowIndex]
        this.$refs.xTable1.tableData.splice(this.currRowIndex - 1, 1)
        this.$refs.xTable1.tableData.splice(
          this.currRowIndex,
          0,
          upData
        )
        this.currRowIndex = this.currRowIndex - 1
        this.$nextTick(() => {
          this.$refs.xTable1.setCurrentRow(currentrow)
        })
      }
    },
    tabledatadown() {
      if (this.currRowIndex !== this.$refs.xTable1.tableData.length - 1) {
        let downData = this.$refs.xTable1.tableData[
          this.currRowIndex + 1
        ]
        let currentrow = this.$refs.xTable1.tableData[this.currRowIndex]
        this.$refs.xTable1.tableData.splice(this.currRowIndex + 1, 1)
        this.$refs.xTable1.tableData.splice(
          this.currRowIndex,
          0,
          downData
        )
        this.currRowIndex = this.currRowIndex + 1
        this.$nextTick(() => {
          this.$refs.xTable1.setCurrentRow(currentrow)
        })
      }
    },
    tabledatalast() {
      if (this.currRowIndex != this.$refs.xTable1.tableData.length - 1) {
        let lastData = this.$refs.xTable1.tableData[this.currRowIndex]
        this.$refs.xTable1.tableData.splice(this.currRowIndex, 1)
        this.$refs.xTable1.tableData.splice(
          this.$refs.xTable1.tableData.length,
          0,
          lastData
        )
        this.currRowIndex = this.$refs.xTable1.tableData.length - 1
        this.$nextTick(() => {
          this.$refs.xTable1.setCurrentRow(lastData)
        })
      }
    },
    tabledatafirst() {
      if (this.currRowIndex > 0) {
        let firstData = this.$refs.xTable1.tableData[this.currRowIndex]
        this.$refs.xTable1.tableData.splice(this.currRowIndex, 1)
        this.$refs.xTable1.tableData.splice(0, 0, firstData)
        this.currRowIndex = 0
        this.$nextTick(() => {
          this.$refs.xTable1.setCurrentRow(firstData)
        })
      }
    },
    handleCommand(name) {
      this.datename = name
      if (name == "标本日期") {
        this.daytype = "1"
      } else {
        this.daytype = "2"
      }
    },
    async initOption() {
      try {
        const res = await this.$tool.request({
          url: "LIS/LIS9/LIS921",
          method: "post",
          data: {
            action: "getOption",
          },
        })
        this.deptgroupOption = res.deptgroupOption
        this.germcombOption = res.germcombOption
        this.pattypeOption = res.pattypeOption
        this.deptOption = res.deptOption
        this.hospOption = res.hospOption
        this.doctorOption = res.doctorOption
        this.rptunitOption = res.rptunitOption
        this.rptunitGroupOption = res.rptunitGroupOption
        this.reportcommOption = res.reportcommOption
        this.wardOption = res.wardOption
        this.labgroupOption = res.labgroupOption
        this.specimenOption = res.specimenOption
        this.userOption = res.userOption
        this.rescodeOption = res.rescodeOption
      } catch (e) {
        this.$message.warning(e)
      }
    },
    btnQuery() {
      this.InitPage()
    },
    btnSort() {
      this.$rmsort(
        { tableColumn: this.SortTableColumn, sortArr: this.sortArr },
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then((res) => {
          this.sortArr = res.data
          this.InitPage()
        })
        .catch(() => { })
    },
    btnClear() {
      this.initdate()
      this.searchobj = {
        strdate: this.$pub.InitDateTime2(0).datefrom,
        enddate: this.$pub.InitDateTime2(0).dateto,
        reqdept: "",
        germcomb: "",
        resistrule: "",
        reqward: "",
        sample: "",
        rptunitid: "",
        deptgroup: "",
        patsex: "",
        pattype: "",
        bytype: "",
        bypat: "",
        nogermflag: "0",
        deptmode: "0",
        germflag: "",
      }
      // this.strdate = ""
      // this.enddate = ""
      // this.reqdept = ""
      // this.germcomb = ""
      // this.resistrule = ""
      // this.reqward = ""
      // this.sample = ""
      // this.rptunitid = ""
      // this.deptgroup = ""
      // this.patsex = ""
      // this.pattype = ""
      // this.bytype = ""
      // this.bypat = ""
      // this.nogermflag = "0"
      // this.deptmode = "0"
      this.tableData = []
    },
    btnExport() {
      let data = this.getExportData();
      let filtertxt = this.getExportFilter();
      this.$pub.exportTableExcelWithData(data, this.exportTableColLen, "LIS921 细菌分布-按标本.xlsx", filtertxt, "统计条件：");
    },
    // 获取当前导出文件的所有查询条件
    getExportFilter() {
      let filtertxt = this.datename + ":" + XEUtils.toDateString(this.searchobj.strdate, "yyyy-MM-dd") + "至" + XEUtils.toDateString(this.searchobj.enddate, "yyyy-MM-dd") + "; ";
      if (this.searchobj.reqdept) filtertxt += "科室:" + this.getOptionName(this.deptOption.filter((item) => ("," + this.searchobj.reqdept + ",").indexOf("," + item.data + ",") > -1)) + "; ";
      if (this.searchobj.germcomb) filtertxt += "菌组:" + this.getOptionName(this.germcombOption.filter((item) => ("," + this.searchobj.germcomb + ",").indexOf("," + item.data + ",") > -1)) + "; ";
      if (this.searchobj.resistrule) filtertxt += "耐药机制:" + this.getOptionName(this.rescodeOption.filter((item) => ("," + this.searchobj.resistrule + ",").indexOf("," + item.data + ",") > -1)) + "; ";
      if (this.searchobj.reqward) filtertxt += "病区:" + this.getOptionName(this.wardOption.filter((item) => ("," + this.searchobj.reqward + ",").indexOf("," + item.data + ",") > -1)) + "; ";
      if (this.searchobj.sample) filtertxt += "样本:" + this.getOptionName(this.searchobj.nogermflag == "0" ? (this.specimenOption.filter((item) => ("," + this.searchobj.sample + ",").indexOf("," + item.data + ",") > -1)) : (this.nogermOption.filter((item) => ("," + this.searchobj.sample + ",").indexOf("," + item.data + ",") > -1))) + "; ";
      if (this.searchobj.rptunitid) filtertxt += "报告单元:" + this.getOptionName(this.rptunitOption.filter((item) => ("," + this.searchobj.rptunitid + ",").indexOf("," + item.data + ",") > -1)) + "; ";
      if (this.searchobj.deptgroup) filtertxt += "科室组:" + this.getOptionName(this.deptgroupOption.filter((item) => ("," + this.searchobj.deptgroup + ",").indexOf("," + item.data + ",") > -1)) + "; ";
      if (this.searchobj.patsex) filtertxt += "性别:" + (this.searchobj.patsex == "1" ? "男" : this.searchobj.patsex == "2" ? "女" : "未知") + "; ";
      if (this.searchobj.pattype) filtertxt += "病人类型:" + this.pattypename + "; ";
      if (this.searchobj.bypat == "1") filtertxt += "按病人统计; ";
      if (this.searchobj.nogermflag == "1") filtertxt += "仅显示无菌样本; ";
      if (this.infocode) filtertxt += "统计项目:" + this.infoitem + "; ";
      if (this.searchobj.germflag) filtertxt += "细菌标志:" + this.getGermFlagName() + "; ";
      if (this.searchobj.medflag == "1") filtertxt += "仅显示带药敏; ";
      return filtertxt;
    },
    getGermFlagName() {
      let name = "";
      switch (this.searchobj.germflag) {
        case "1":
          name = "培养阴性结果";
          break;
        case "2":
          name = "致病菌";
          break;
        case "3":
          name = "正常菌种";
          break;
        case "4":
          name = "正常菌种";
          break;
        default:
          name = "普通项目";
          break;
      }
      return name;
    },
    getOptionName(option) {
      if (option && option.length > 0) {
        let optionname = "";
        option.forEach((item) => {
          if (item.hasOwnProperty("display")) {
            optionname += item.display + ",";
          } else {
            optionname += item.label + ",";
          }
        });
        return optionname.substring(0, optionname.length - 1);
      } else {
        return "";
      }
    },
    getExportData() {
      let datas = this.tableData;
      this.exportTableColLen = this.tableColumn.length;
      let columns = this.tableColumn.filter((item) => item.field);
      let headers = [columns.map((item) => item.name)];
      return headers.concat(
        datas.map((row) => {
          return columns.map((column) => {
            if (column.field == "rp_req_wardno") {
              let wardname = this.wardOption.find(
                (m) => m.data == row[column.field]
              )
              if (wardname != undefined && wardname != null) {
                row[column.field] = wardname.display
              }
            }
            if (column.field == "rp_req_deptno") {
              let deptname = this.deptOption.find(
                (m) => m.data == row[column.field]
              )
              if (deptname != undefined && deptname != null) {
                row[column.field] = deptname.display
              }
            }
            return row[column.field]
          })
        })
      )
    },
    // BtnPrint() {},
    async InitPage() {
      this.tableColumn = []
      this.bLoading = true
      this.$tool
        .request({
          url: "LIS/LIS9/LIS921",
          method: "post",
          timeout: 600000,
          data: {
            action: "query",
            daytype: this.daytype, //标本日期(1) 报告日期(2)
            infocode: this.infocode, //要查询的列数
            sortArr: this.sortArr, //排序
            ...this.searchobj,
          },
        })
        .then((response) => {
          ++this.xTablekey
          var colobj = response.Data[0]
          var colkey = []
          for (var p in colobj) {
            if (colobj.hasOwnProperty(p)) {
              if (p == "rp_rpt_itemname") {
                colkey.push({
                  name: "细菌名称",
                  field: p,
                  width: "130",
                  align: "center",
                })
              } else if (p == "rp_req_wardno") {
                colkey.push({
                  name: "病区",
                  field: p,
                  width: "150",
                  align: "left",
                })
              } else if (p == "rp_req_deptno") {
                colkey.push({
                  name: "科室",
                  field: p,
                  width: "150",
                  align: "left",
                })
              } else if (p == "rp_sampleyear") {
                colkey.push({
                  name: "年",
                  field: p,
                  width: "40",
                  align: "center",
                })
              } else if (p == "rp_samplemonth") {
                colkey.push({
                  name: "月",
                  field: p,
                  width: "60",
                  align: "center",
                })
              } else if (p == "rp_sampleday") {
                colkey.push({
                  name: "日",
                  field: p,
                  width: "100",
                  align: "center",
                })
              } else {
                colkey.push({
                  name: p,
                  field: p,
                  width: "60",
                  align: "center",
                })
              }
            }
          }
          this.tableColumn = colkey
          this.tableData = response.Data
          this.bLoading = false
          // if (response.RData.Data.length > 0) {
          //     ++this.xTablekey;
          //     this.tableColumn = response.RData.Cols;
          //     this.tableData = response.RData.Data;
          // } else {
          //     this.$alert("没有查询到符合条件的资料！", "信息", { confirmButtonText: "确定" });
          // }
        })
        .catch((e) => {
          this.bLoading = false
          this.$message.warning(e)
        })
    },
    xTable1dblclick({ row, column }) {
      this[row.countcode] = false
      try {
        var delrow = this.$refs.xTable1.getCurrentRow()
        if (delrow) {
          var alld = this.$refs.xTable1.tableData
          var rowindex = alld.indexOf(delrow)
          this.$refs.xTable1.remove(delrow)
          let havedata = this.$refs.xTable1.tableData
          if (havedata.length > 0) {
            if (rowindex >= havedata.length)
              rowindex = havedata.length - 1
            let selectrow = havedata[rowindex]
            this.$refs.xTable1.setCurrentRow(selectrow)
          }
        }
      } catch (e) {
        console.log("error", e)
      }
    },
    formatFun({ cellValue, column, row }) {
      if (["rp_req_wardno"].includes(column.property)) {
        try {
          let wardname = this.wardOption.find(
            (m) => m.data == cellValue
          )
          if (wardname != undefined && wardname != null) {
            return wardname.display
          } else {
            return cellValue
          }
        } catch { }
      } else if (["rp_req_deptno"].includes(column.property)) {
        try {
          let deptname = this.deptOption.find(
            (m) => m.data == cellValue
          )
          if (deptname != undefined && deptname != null) {
            return deptname.display
          } else {
            return cellValue
          }
        } catch { }
      } else {
        return cellValue
      }
    },
    cellClassName({ row, column }) {
      if (![
        "rp_rpt_itemname",
        "rp_req_wardno",
        "rp_req_deptno",
        "rp_sampleyear",
        "rp_samplemonth",
        "rp_sampleday",
        "检出数",
        "检出人数",
      ].includes(column.property)) {
        if (parseInt(row[column.property]) > 0) {
          return "sample-tips";
        }
      }
    },
    footerCellClassName({ $rowIndex, column, columnIndex }) {
      if (
        columnIndex === 0 ||
        ![
          "rp_rpt_itemname",
          "rp_req_wardno",
          "rp_req_deptno",
          "rp_sampleyear",
          "rp_samplemonth",
          "rp_sampleday",
        ].includes(column.property)
      ) {
        if ($rowIndex === 0) {
          return "col-blue"
        } else {
          return "col-red"
        }
      }
    },
    footerMethod({ columns, data }) {
      return [
        columns.map((column, columnIndex) => {
          if (columnIndex === 0) {
            return "总计"
          }
          if (
            ![
              "rp_rpt_itemname",
              "rp_req_wardno",
              "rp_req_deptno",
              "rp_sampleyear",
              "rp_samplemonth",
              "rp_sampleday",
            ].includes(column.property)
          ) {
            return XEUtils.sum(data, column.property)
          }
          return null
        }),
      ]
    },
    tableClear() {
      this.rp_req_deptno = false
      this.rp_req_wardno = false
      this.rp_rpt_itemname = false
      this.rp_rpt_itemcode = false
      this.rp_sampleyear = false
      this.rp_samplemonth = false
      this.rp_sampleday = false
      this.tableData1 = []
    },
    dialogcountItemsave() {
      let data = this.$refs.xTable1.tableData
      let res1 = ""
      let res2 = ""
      if (data.length > 0) {
        data.forEach((element) => {
          if (res2 == "") {
            res2 = element.countitem
            res1 = element.countcode
          } else {
            res2 += "," + element.countitem
            res1 += "," + element.countcode
          }
        })
      }
      this.infoitem = res2
      this.infocode = res1
      this.dialogcountItem = false
    },
    deptchange() { },
    wardchange() { },
    specimenchange() { },
    rptunitChange() { },
    pattypeChange(code, name) {
      this.searchobj.pattype = code;
      this.pattypename = name;
    },
    resistruleChange() { },
    deptgroupChange() { },
  },
}
</script>

<style scoped>
.pagetop {
  width: 100%;
  height: 130px;
  display: -webkit-box;
  -webkit-box-pack: left;
  -webkit-box-align: center;
  border: 1px solid #ccc;
  position: absolute;
  z-index: 99;
}

.pagecenter {
  position: absolute;
  top: 135px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}

.middle-center {
  position: absolute;
  height: 100%;
  left: 0px;
  right: 0px;
  overflow: auto;
}

.el-checkbox__label {
  padding: 0px;
}

table {
  font-size: 12px;
  border-collapse: separate;
  border-spacing: 5px;
}

.left_nav {
  width: 20%;
  height: 100%;
  border-right: 1px solid #ccc;
  padding: 0px 0px 0px 0px;
  float: left;
  display: inline;
}

.left_nav div {
  cursor: pointer;
  height: 40px;
  width: 100%;
  float: left;
  padding-left: 20px;
  line-height: 40px;
}

.left_nav .active {
  background-color: DeepSkyBlue;
}

.right_nav {
  width: 80%;
  height: 100%;
  display: inline-block;
  vertical-align: top;
  float: left;
  display: inline;
}

.table1style tr td {
  padding: 0px 2px 0px 5px;
}

::v-deep .mytable-style .vxe-footer--column.col-blue {
  color: blue !important;
  font-weight: bold;
}

::v-deep .mytable-style .vxe-body--row.row-blue {
  color: blue !important;
  font-weight: bold;
}

::v-deep .el-checkbox__label {
  padding-left: 0px;
}

::v-deep .el-icon-time {
  line-height: 18px !important;
}

::v-deep .el-range__close-icon {
  line-height: 18px !important;
}

::v-deep .el-range-editor--small .el-range-separator {
  line-height: 17px !important;
}

::v-deep.el-input--suffix .el-input__inner {
  padding-right: 0px;
}

::v-deep .sample-tips {
  color: blue;
  cursor: pointer;
  text-decoration: underline;
}</style>
